import util from '@ohos.util';

export class CodeStr{

  /**
   * string 转 Uint8Array
   * @param msg
   * @returns
   */
  static  strToU8Array(msg:string):Uint8Array{
     let textEncoder = new util.TextEncoder();
     let uint8Array2 = textEncoder.encodeInto(msg);
		 return uint8Array2 ;
	 }


   /**
    * @param base64String
    */
   static async base64ToStr(base64String:string): Promise<string>{
     // 创建 Base64 工具类实例
     const base64 = new util.Base64Helper();
     // 将 Base64 字符串解码为 Uint8Array
     const uint8Array = await base64.decode(base64String);
     // 将 Uint8Array 转换为普通字符串
     const textDecoder = new util.TextDecoder();
     const result= textDecoder.decodeWithStream(uint8Array);
     return result.toString()
   }

}